package com.youyi.yychosesdk.ui;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.yanzhenjie.permission.runtime.Permission;
import com.youyi.yychosesdk.EasyPhotos;
import com.lkx.liandianqinew.R;
import com.youyi.yychosesdk.constant.Key;
import com.youyi.yychosesdk.constant.Type;
import com.youyi.yychosesdk.models.album.AlbumModel;
import com.youyi.yychosesdk.models.album.entity.Photo;
import com.youyi.yychosesdk.result.Result;
import com.youyi.yychosesdk.setting.Setting;
import com.youyi.yychosesdk.ui.adapter.AlbumItemsAdapter;
import com.youyi.yychosesdk.ui.adapter.PhotosAdapter;
import com.youyi.yychosesdk.ui.dialog.LoadingDialog;
import com.youyi.yychosesdk.ui.widget.PressedTextView;
import com.youyi.yychosesdk.utils.Color.ColorUtils;
import com.youyi.yychosesdk.utils.String.StringUtils;
import com.youyi.yychosesdk.utils.bitmap.BitmapUtils;
import com.youyi.yychosesdk.utils.media.DurationUtils;
import com.youyi.yychosesdk.utils.media.MediaScannerConnectionUtils;
import com.youyi.yychosesdk.utils.permission.PermissionUtil;
import com.youyi.yychosesdk.utils.settings.SettingsUtils;
import com.youyi.yychosesdk.utils.system.SystemUtils;
import com.youyi.yychosesdk.utils.uri.UriUtils;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

public class EasyPhotosActivity extends AppCompatActivity implements AlbumItemsAdapter.OnClickListener, PhotosAdapter.OnClickListener, View.OnClickListener {
    public static long startTime;
    private ArrayList<Object> albumItemList = new ArrayList<>();
    private AlbumItemsAdapter albumItemsAdapter;
    private AlbumModel albumModel;
    String albumName;
    private boolean clickDone = false;
    private int currAlbumItemIndex = 0;
    String folderPath;
    private GridLayoutManager gridLayoutManager;
    private boolean isQ = false;
    private ImageView ivCamera;
    LoadingDialog loadingDialog;
    private View mBottomBar;
    private LinearLayout mSecondMenus;
    private File mTempImageFile;
    private RelativeLayout permissionView;
    private ArrayList<Object> photoList = new ArrayList<>();
    private PhotosAdapter photosAdapter;
    private ArrayList<Photo> resultList = new ArrayList<>();
    private RelativeLayout rootViewAlbumItems;
    private RecyclerView rvAlbumItems;
    private RecyclerView rvPhotos;
    private AnimatorSet setHide;
    private AnimatorSet setShow;
    private PressedTextView tvAlbumItems;
    private PressedTextView tvDone;
    private TextView tvOriginal;
    private TextView tvPermission;
    private PressedTextView tvPreview;
    private TextView tvTitle;

    public static boolean doubleClick() {
        long currentTimeMillis = System.currentTimeMillis();
        if (currentTimeMillis - startTime < 600) {
            return true;
        }
        startTime = currentTimeMillis;
        return false;
    }

    public static void start(Activity activity, int i) {
        if (!doubleClick()) {
            activity.startActivityForResult(new Intent(activity, EasyPhotosActivity.class), i);
        }
    }

    public static void start(Fragment fragment, int i) {
        if (!doubleClick()) {
            fragment.startActivityForResult(new Intent(fragment.getActivity(), EasyPhotosActivity.class), i);
        }
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v4.app.SupportActivity, android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_easy_photos);
        hideActionBar();
        adaptationStatusBar();
        this.loadingDialog = LoadingDialog.get(this);
        this.isQ = Build.VERSION.SDK_INT == 29;
        if (Setting.onlyStartCamera || Setting.imageEngine != null) {
            initSomeViews();
            if (PermissionUtil.checkAndRequestPermissionsInActivity(this, getNeedPermissions())) {
                hasPermissions();
            } else {
                this.permissionView.setVisibility(View.VISIBLE);
            }
        } else {
            finish();
        }
    }

    private void adaptationStatusBar() {
        if (Build.VERSION.SDK_INT >= 23) {
            int statusBarColor = getWindow().getStatusBarColor();
            if (statusBarColor == 0) {
                statusBarColor = ContextCompat.getColor(this, R.color.colorPrimaryDark);
            }
            if (ColorUtils.isWhiteColor(statusBarColor)) {
                SystemUtils.getInstance().setStatusDark(this, true);
            }
        }
    }

    private void initSomeViews() {
        this.mBottomBar = findViewById(R.id.m_bottom_bar);
        this.permissionView = (RelativeLayout) findViewById(R.id.rl_permissions_view);
        this.tvPermission = (TextView) findViewById(R.id.tv_permission);
        this.rootViewAlbumItems = (RelativeLayout) findViewById(R.id.root_view_album_items);
        this.tvTitle = (TextView) findViewById(R.id.tv_title);
        if (Setting.isOnlyVideo()) {
            this.tvTitle.setText(R.string.video_selection_easy_photos);
        }
        findViewById(R.id.iv_second_menu).setVisibility((Setting.showCleanMenu || Setting.showOriginalMenu) ? View.VISIBLE : View.GONE);
        setClick(R.id.iv_back);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void hasPermissions() {
        this.permissionView.setVisibility(View.GONE);
        if (Setting.onlyStartCamera) {
            launchCamera(11);
            return;
        }
        AlbumModel.CallBack r0 = new AlbumModel.CallBack() {
            /* class com.youyi.yychosesdk.ui.EasyPhotosActivity.AnonymousClass1 */

            @Override // com.youyi.yychosesdk.models.album.AlbumModel.CallBack
            public void onAlbumWorkedCallBack() {
                EasyPhotosActivity.this.runOnUiThread(new Runnable() {
                    /* class com.youyi.yychosesdk.ui.EasyPhotosActivity.AnonymousClass1.AnonymousClass1 */

                    public void run() {
                        EasyPhotosActivity.this.loadingDialog.dismiss();
                        EasyPhotosActivity.this.onAlbumWorkedDo();
                    }
                });
            }
        };
        this.loadingDialog.show();
        AlbumModel instance = AlbumModel.getInstance();
        this.albumModel = instance;
        instance.query(this, r0);
    }

    /* access modifiers changed from: protected */
    public String[] getNeedPermissions() {
        if (Setting.isShowCamera) {
            if (Setting.onlyStartCamera) {
                return new String[]{Permission.CAMERA};
            }
            if (Build.VERSION.SDK_INT >= 16) {
                return new String[]{Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE, Permission.READ_EXTERNAL_STORAGE};
            }
            return new String[]{Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE};
        } else if (Build.VERSION.SDK_INT >= 16) {
            return new String[]{Permission.WRITE_EXTERNAL_STORAGE, Permission.READ_EXTERNAL_STORAGE};
        } else {
            return new String[]{Permission.WRITE_EXTERNAL_STORAGE};
        }
    }

    @Override // android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback, android.support.v4.app.FragmentActivity
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        super.onRequestPermissionsResult(i, strArr, iArr);
        PermissionUtil.onPermissionResult(this, strArr, iArr, new PermissionUtil.PermissionCallBack() {
            /* class com.youyi.yychosesdk.ui.EasyPhotosActivity.AnonymousClass2 */

            @Override // com.youyi.yychosesdk.utils.permission.PermissionUtil.PermissionCallBack
            public void onSuccess() {
                EasyPhotosActivity.this.hasPermissions();
            }

            @Override // com.youyi.yychosesdk.utils.permission.PermissionUtil.PermissionCallBack
            public void onShouldShow() {
                EasyPhotosActivity.this.tvPermission.setText(R.string.permissions_again_easy_photos);
                EasyPhotosActivity.this.permissionView.setOnClickListener(new View.OnClickListener() {
                    /* class com.youyi.yychosesdk.ui.EasyPhotosActivity.AnonymousClass2.AnonymousClass1 */

                    public void onClick(View view) {
                        if (PermissionUtil.checkAndRequestPermissionsInActivity(EasyPhotosActivity.this, EasyPhotosActivity.this.getNeedPermissions())) {
                            EasyPhotosActivity.this.hasPermissions();
                        }
                    }
                });
            }

            @Override // com.youyi.yychosesdk.utils.permission.PermissionUtil.PermissionCallBack
            public void onFailed() {
                EasyPhotosActivity.this.tvPermission.setText(R.string.permissions_die_easy_photos);
                EasyPhotosActivity.this.permissionView.setOnClickListener(new View.OnClickListener() {
                    /* class com.youyi.yychosesdk.ui.EasyPhotosActivity.AnonymousClass2.AnonymousClass2 */

                    public void onClick(View view) {
                        SettingsUtils.startMyApplicationDetailsForResult(EasyPhotosActivity.this, EasyPhotosActivity.this.getPackageName());
                    }
                });
            }
        });
    }

    private void launchCamera(int i) {
        if (TextUtils.isEmpty(Setting.fileProviderAuthority)) {
            throw new RuntimeException("AlbumBuilder : 请执行 setFileProviderAuthority()方法");
        } else if (!cameraIsCanUse()) {
            this.permissionView.setVisibility(View.VISIBLE);
            this.tvPermission.setText(R.string.permissions_die_easy_photos);
            this.permissionView.setOnClickListener(new View.OnClickListener() {
                /* class com.youyi.yychosesdk.ui.EasyPhotosActivity.AnonymousClass3 */

                public void onClick(View view) {
                    EasyPhotosActivity easyPhotosActivity = EasyPhotosActivity.this;
                    SettingsUtils.startMyApplicationDetailsForResult(easyPhotosActivity, easyPhotosActivity.getPackageName());
                }
            });
        } else {
            toAndroidCamera(i);
        }
    }

    public static String createID() {
        return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date(System.currentTimeMillis()));
    }

    private void toAndroidCamera(int i) {
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        if (intent.resolveActivity(getPackageManager()) != null || getPackageManager().hasSystemFeature("android.hardware.camera.any")) {
            try {
                File filesDir = getFilesDir();
                File file = new File(filesDir, createID() + ".jpg");
                this.mTempImageFile = file;
                if (!file.exists()) {
                    new File(this.mTempImageFile.getParent()).mkdirs();
                    this.mTempImageFile.createNewFile();
                }
            } catch (Exception unused) {
            }
            Log.d("拍照地址01=", this.mTempImageFile.getAbsolutePath());
            File file2 = this.mTempImageFile;
            if (file2 == null || !file2.isFile()) {
                Toast.makeText(getApplicationContext(), R.string.camera_temp_file_error_easy_photos, 0).show();
                return;
            }
            Uri uri = UriUtils.getUri(this, this.mTempImageFile);
           intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            intent.putExtra("output", uri);
            startActivityForResult(intent, i);
            return;
        }
        Toast.makeText(getApplicationContext(), R.string.msg_no_camera_easy_photos, 0).show();
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v4.app.FragmentActivity
    public void onActivityResult(int i, int i2, Intent intent) {
        if (i == 14) {
            if (PermissionUtil.checkAndRequestPermissionsInActivity(this, getNeedPermissions())) {
                hasPermissions();
            } else {
                this.permissionView.setVisibility(View.VISIBLE);
            }
        } else if (i2 != -1) {
            if (i2 == 0) {
                if (11 == i) {
                    File file = this.mTempImageFile;
                    if (file != null && file.exists()) {
                        this.mTempImageFile.delete();
                        this.mTempImageFile = null;
                    }
                    if (Setting.onlyStartCamera) {
                        finish();
                    }
                } else if (13 == i) {
                    processOriginalMenu();
                }
            }
        } else if (11 == i) {
            File file2 = this.mTempImageFile;
            if (file2 == null || !file2.isFile()) {
                throw new RuntimeException("EasyPhotos拍照保存的图片不存在");
            }
            onCameraResult();
        } else if (13 != i) {
        } else {
            if (intent.getBooleanExtra(Key.PREVIEW_CLICK_DONE, false)) {
                done();
                return;
            }
            this.photosAdapter.change();
            processOriginalMenu();
            shouldShowMenuDone();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void addNewPhoto(Photo photo) {
        photo.selectedOriginal = Setting.selectedOriginal;
        if (!this.isQ) {
            MediaScannerConnectionUtils.refresh(this, photo.path);
            String absolutePath = new File(photo.path).getParentFile().getAbsolutePath();
            this.folderPath = absolutePath;
            this.albumName = StringUtils.getLastPathSegment(absolutePath);
        }
        this.albumModel.album.getAlbumItem(this.albumModel.getAllAlbumName(this)).addImageItem(0, photo);
        this.albumModel.album.addAlbumItem(this.albumName, this.folderPath, photo.path, photo.uri);
        this.albumModel.album.getAlbumItem(this.albumName).addImageItem(0, photo);
        this.albumItemList.clear();
        this.albumItemList.addAll(this.albumModel.getAlbumItems());
        this.albumItemsAdapter.notifyDataSetChanged();
        if (Setting.count == 1) {
            Result.clear();
            onSelectorOutOfMax(Integer.valueOf(Result.addPhoto(photo)));
        } else if (Result.count() >= Setting.count) {
            onSelectorOutOfMax(null);
        } else {
            onSelectorOutOfMax(Integer.valueOf(Result.addPhoto(photo)));
        }
        this.rvAlbumItems.scrollToPosition(0);
        this.albumItemsAdapter.setSelectedPosition(0);
        shouldShowMenuDone();
    }

    private Photo getPhoto(Uri uri) {
        int i;
        int i2;
        int i3;
        String[] projections = AlbumModel.getInstance().getProjections();
        boolean z = projections.length > 8;
        Cursor query = getContentResolver().query(uri, projections, null, null, null);
        Photo photo = null;
        if (query == null) {
            return null;
        }
        int columnIndex = query.getColumnIndex("bucket_display_name");
        if (query.moveToFirst()) {
            String string = query.getString(1);
            String string2 = query.getString(2);
            long j = query.getLong(3);
            String string3 = query.getString(4);
            long j2 = query.getLong(5);
            if (z) {
                int i4 = query.getInt(query.getColumnIndex("width"));
                int i5 = query.getInt(query.getColumnIndex("height"));
                int i6 = query.getInt(query.getColumnIndex("orientation"));
                if (90 == i6 || 270 == i6) {
                    i3 = i5;
                    i = i6;
                    i2 = i4;
                } else {
                    i2 = i5;
                    i = i6;
                    i3 = i4;
                }
            } else {
                i3 = 0;
                i2 = 0;
                i = 0;
            }
            if (columnIndex > 0) {
                String string4 = query.getString(columnIndex);
                this.albumName = string4;
                this.folderPath = string4;
            }
            photo = new Photo(string2, uri, string, j, i3, i2, i, j2, 0, string3);
        }
        query.close();
        return photo;
    }

    private void onCameraResult() {
        LoadingDialog.get(this);
        new Thread(new Runnable() {
            /* class com.youyi.yychosesdk.ui.EasyPhotosActivity.AnonymousClass4 */

            public void run() {
                int i;
                int i2;
                int i3;
                File file = new File(EasyPhotosActivity.this.mTempImageFile.getParentFile(), String.format("IMG_%s.jpg", new SimpleDateFormat("yyyyMMdd_HH_mm_ss", Locale.getDefault()).format(new Date())));
                if (!file.exists() && EasyPhotosActivity.this.mTempImageFile.renameTo(file)) {
                    EasyPhotosActivity.this.mTempImageFile = file;
                }
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeFile(EasyPhotosActivity.this.mTempImageFile.getAbsolutePath(), options);
                EasyPhotosActivity easyPhotosActivity = EasyPhotosActivity.this;
                MediaScannerConnectionUtils.refresh(easyPhotosActivity, easyPhotosActivity.mTempImageFile);
                EasyPhotosActivity easyPhotosActivity2 = EasyPhotosActivity.this;
                Uri uri = UriUtils.getUri(easyPhotosActivity2, easyPhotosActivity2.mTempImageFile);
                if (Setting.useWidth) {
                    int i4 = options.outWidth;
                    int i5 = options.outHeight;
                    ExifInterface exifInterface = null;
                    try {
                        exifInterface = new ExifInterface(EasyPhotosActivity.this.mTempImageFile);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    if (exifInterface != null) {
                        int attributeInt = exifInterface.getAttributeInt(android.support.media.ExifInterface.TAG_ORIENTATION, -1);
                        if (attributeInt == 6 || attributeInt == 8) {
                            i3 = options.outHeight;
                            i2 = options.outWidth;
                            i = attributeInt;
                        } else {
                            i3 = i4;
                            i = attributeInt;
                            i2 = i5;
                        }
                        final Photo photo = new Photo(EasyPhotosActivity.this.mTempImageFile.getName(), uri, EasyPhotosActivity.this.mTempImageFile.getAbsolutePath(), EasyPhotosActivity.this.mTempImageFile.lastModified() / 1000, i3, i2, i, EasyPhotosActivity.this.mTempImageFile.length(), DurationUtils.getDuration(EasyPhotosActivity.this.mTempImageFile.getAbsolutePath()), options.outMimeType);
                        EasyPhotosActivity.this.runOnUiThread(new Runnable() {
                            /* class com.youyi.yychosesdk.ui.EasyPhotosActivity.AnonymousClass4.AnonymousClass1 */

                            public void run() {
                                if (Setting.onlyStartCamera || EasyPhotosActivity.this.albumModel.getAlbumItems().isEmpty()) {
                                    Intent intent = new Intent();
                                    photo.selectedOriginal = Setting.selectedOriginal;
                                    EasyPhotosActivity.this.resultList.add(photo);
                                    intent.putParcelableArrayListExtra(EasyPhotos.RESULT_PHOTOS, EasyPhotosActivity.this.resultList);
                                    intent.putExtra(EasyPhotos.RESULT_SELECTED_ORIGINAL, Setting.selectedOriginal);
                                    EasyPhotosActivity.this.setResult(-1, intent);
                                    EasyPhotosActivity.this.finish();
                                    return;
                                }
                                EasyPhotosActivity.this.addNewPhoto(photo);
                            }
                        });
                    }
                    i3 = i4;
                    i2 = i5;
                } else {
                    i3 = 0;
                    i2 = 0;
                }
                i = 0;
                final Photo photo2 = new Photo(EasyPhotosActivity.this.mTempImageFile.getName(), uri, EasyPhotosActivity.this.mTempImageFile.getAbsolutePath(), EasyPhotosActivity.this.mTempImageFile.lastModified() / 1000, i3, i2, i, EasyPhotosActivity.this.mTempImageFile.length(), DurationUtils.getDuration(EasyPhotosActivity.this.mTempImageFile.getAbsolutePath()), options.outMimeType);
                EasyPhotosActivity.this.runOnUiThread(new Runnable() {
                    /* class com.youyi.yychosesdk.ui.EasyPhotosActivity.AnonymousClass4.AnonymousClass1 */

                    public void run() {
                        if (Setting.onlyStartCamera || EasyPhotosActivity.this.albumModel.getAlbumItems().isEmpty()) {
                            Intent intent = new Intent();
                            photo2.selectedOriginal = Setting.selectedOriginal;
                            EasyPhotosActivity.this.resultList.add(photo2);
                            intent.putParcelableArrayListExtra(EasyPhotos.RESULT_PHOTOS, EasyPhotosActivity.this.resultList);
                            intent.putExtra(EasyPhotos.RESULT_SELECTED_ORIGINAL, Setting.selectedOriginal);
                            EasyPhotosActivity.this.setResult(-1, intent);
                            EasyPhotosActivity.this.finish();
                            return;
                        }
                        EasyPhotosActivity.this.addNewPhoto(photo2);
                    }
                });
            }
        }).start();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void onAlbumWorkedDo() {
        initView();
    }

    private void initView() {
        if (!this.albumModel.getAlbumItems().isEmpty()) {
            this.ivCamera = (ImageView) findViewById(R.id.fab_camera);
            if (Setting.isShowCamera && Setting.isBottomRightCamera()) {
                this.ivCamera.setVisibility(View.VISIBLE);
            }
            this.mSecondMenus = (LinearLayout) findViewById(R.id.m_second_level_menu);
            int integer = getResources().getInteger(R.integer.photos_columns_easy_photos);
            PressedTextView pressedTextView = (PressedTextView) findViewById(R.id.tv_album_items);
            this.tvAlbumItems = pressedTextView;
            pressedTextView.setText(this.albumModel.getAlbumItems().get(0).name);
            this.tvDone = (PressedTextView) findViewById(R.id.tv_done);
            RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv_photos);
            this.rvPhotos = recyclerView;
            ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
            this.photoList.clear();
            this.photoList.addAll(this.albumModel.getCurrAlbumItemPhotos(0));
            if (Setting.isShowCamera && !Setting.isBottomRightCamera()) {
                this.photoList.add(0, null);
            }
            this.photosAdapter = new PhotosAdapter(this, this.photoList, this);
            GridLayoutManager gridLayoutManager2 = new GridLayoutManager(this, integer);
            this.gridLayoutManager = gridLayoutManager2;
            this.rvPhotos.setLayoutManager(gridLayoutManager2);
            this.rvPhotos.setAdapter(this.photosAdapter);
            this.tvOriginal = (TextView) findViewById(R.id.tv_original);
            if (Setting.showOriginalMenu) {
                processOriginalMenu();
            } else {
                this.tvOriginal.setVisibility(View.GONE);
            }
            this.tvPreview = (PressedTextView) findViewById(R.id.tv_preview);
            initAlbumItems();
            shouldShowMenuDone();
            setClick(R.id.iv_album_items, R.id.tv_clear, R.id.iv_second_menu);
            setClick(this.tvAlbumItems, this.rootViewAlbumItems, this.tvDone, this.tvOriginal, this.tvPreview, this.ivCamera);
        } else if (Setting.isOnlyVideo()) {
            Toast.makeText(getApplicationContext(), R.string.no_videos_easy_photos, 1).show();
            finish();
        } else {
            Toast.makeText(getApplicationContext(), R.string.no_photos_easy_photos, 1).show();
            if (Setting.isShowCamera) {
                launchCamera(11);
            } else {
                finish();
            }
        }
    }

    private void hideActionBar() {
        ActionBar supportActionBar = getSupportActionBar();
        if (supportActionBar != null) {
            supportActionBar.hide();
        }
    }

    private void initAlbumItems() {
        this.rvAlbumItems = (RecyclerView) findViewById(R.id.rv_album_items);
        this.albumItemList.clear();
        this.albumItemList.addAll(this.albumModel.getAlbumItems());
        this.albumItemsAdapter = new AlbumItemsAdapter(this, this.albumItemList, 0, this);
        this.rvAlbumItems.setLayoutManager(new LinearLayoutManager(this));
        this.rvAlbumItems.setAdapter(this.albumItemsAdapter);
    }

    public void onClick(View view) {
        int id = view.getId();
        boolean z = true;
        if (R.id.tv_album_items == id || R.id.iv_album_items == id) {
            if (8 != this.rootViewAlbumItems.getVisibility()) {
                z = false;
            }
            showAlbumItems(z);
        } else if (R.id.root_view_album_items == id) {
            showAlbumItems(false);
        } else if (R.id.iv_back == id) {
            onBackPressed();
        } else if (R.id.tv_done == id) {
            done();
        } else if (R.id.tv_clear == id) {
            if (Result.isEmpty()) {
                processSecondMenu();
                return;
            }
            Result.removeAll();
            this.photosAdapter.change();
            shouldShowMenuDone();
            processSecondMenu();
        } else if (R.id.tv_original == id) {
            if (!Setting.originalMenuUsable) {
                Toast.makeText(getApplicationContext(), Setting.originalMenuUnusableHint, 0).show();
                return;
            }
            Setting.selectedOriginal = !Setting.selectedOriginal;
            processOriginalMenu();
            processSecondMenu();
        } else if (R.id.tv_preview == id) {
            PreviewActivity.start(this, -1, 0);
        } else if (R.id.fab_camera == id) {
            launchCamera(11);
        } else if (R.id.iv_second_menu == id) {
            processSecondMenu();
        }
    }

    public void processSecondMenu() {
        LinearLayout linearLayout = this.mSecondMenus;
        if (linearLayout != null) {
            if (linearLayout.getVisibility() == 0) {
                this.mSecondMenus.setVisibility(View.INVISIBLE);
                if (Setting.isShowCamera && Setting.isBottomRightCamera()) {
                    this.ivCamera.setVisibility(View.VISIBLE);
                    return;
                }
                return;
            }
            this.mSecondMenus.setVisibility(View.VISIBLE);
            if (Setting.isShowCamera && Setting.isBottomRightCamera()) {
                this.ivCamera.setVisibility(View.INVISIBLE);
            }
        }
    }

    private void done() {
        if (!this.clickDone) {
            this.clickDone = true;
            resultFast();
        }
    }

    private void resultUseWidth() {
        this.loadingDialog.show();
        new Thread(new Runnable() {
            /* class com.youyi.yychosesdk.ui.EasyPhotosActivity.AnonymousClass5 */

            public void run() {
                int size = Result.photos.size();
                for (int i = 0; i < size; i++) {
                    try {
                        Photo photo = Result.photos.get(i);
                        if (photo.width == 0 || photo.height == 0) {
                            BitmapUtils.calculateLocalImageSizeThroughBitmapOptions(photo);
                        }
                        if (BitmapUtils.needChangeWidthAndHeight(photo).booleanValue()) {
                            int i2 = photo.width;
                            photo.width = photo.height;
                            photo.height = i2;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                EasyPhotosActivity.this.runOnUiThread(new Runnable() {
                    /* class com.youyi.yychosesdk.ui.EasyPhotosActivity.AnonymousClass5.AnonymousClass1 */

                    public void run() {
                        EasyPhotosActivity.this.loadingDialog.dismiss();
                        EasyPhotosActivity.this.resultFast();
                    }
                });
            }
        }).start();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void resultFast() {
        Intent intent = new Intent();
        Result.processOriginal();
        this.resultList.addAll(Result.photos);
        intent.putParcelableArrayListExtra(EasyPhotos.RESULT_PHOTOS, this.resultList);
        intent.putExtra(EasyPhotos.RESULT_SELECTED_ORIGINAL, Setting.selectedOriginal);
        setResult(-1, intent);
        finish();
    }

    private void processOriginalMenu() {
        if (Setting.showOriginalMenu) {
            if (Setting.selectedOriginal) {
                this.tvOriginal.setTextColor(ContextCompat.getColor(this, R.color.easy_photos_fg_accent));
            } else if (Setting.originalMenuUsable) {
                this.tvOriginal.setTextColor(ContextCompat.getColor(this, R.color.easy_photos_fg_primary));
            } else {
                this.tvOriginal.setTextColor(ContextCompat.getColor(this, R.color.easy_photos_fg_primary_dark));
            }
        }
    }

    private void showAlbumItems(boolean z) {
        if (this.setShow == null) {
            newAnimators();
        }
        if (z) {
            this.rootViewAlbumItems.setVisibility(View.VISIBLE);
            this.setShow.start();
            return;
        }
        this.setHide.start();
    }

    private void newAnimators() {
        newHideAnim();
        newShowAnim();
    }

    private void newShowAnim() {
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(this.rvAlbumItems, "translationY", (float) this.mBottomBar.getTop(), 0.0f);
        ObjectAnimator ofFloat2 = ObjectAnimator.ofFloat(this.rootViewAlbumItems, "alpha", 0.0f, 1.0f);
        ofFloat.setDuration(300L);
        AnimatorSet animatorSet = new AnimatorSet();
        this.setShow = animatorSet;
        animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
        this.setShow.play(ofFloat).with(ofFloat2);
    }

    private void newHideAnim() {
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(this.rvAlbumItems, "translationY", 0.0f, (float) this.mBottomBar.getTop());
        ObjectAnimator ofFloat2 = ObjectAnimator.ofFloat(this.rootViewAlbumItems, "alpha", 1.0f, 0.0f);
        ofFloat.setDuration(200L);
        AnimatorSet animatorSet = new AnimatorSet();
        this.setHide = animatorSet;
        animatorSet.addListener(new AnimatorListenerAdapter() {
            /* class com.youyi.yychosesdk.ui.EasyPhotosActivity.AnonymousClass6 */

            public void onAnimationEnd(Animator animator) {
                super.onAnimationEnd(animator);
                EasyPhotosActivity.this.rootViewAlbumItems.setVisibility(View.GONE);
            }
        });
        this.setHide.setInterpolator(new AccelerateInterpolator());
        this.setHide.play(ofFloat).with(ofFloat2);
    }

    @Override // com.youyi.yychosesdk.ui.adapter.AlbumItemsAdapter.OnClickListener
    public void onAlbumItemClick(int i, int i2) {
        updatePhotos(i2);
        showAlbumItems(false);
        this.tvAlbumItems.setText(this.albumModel.getAlbumItems().get(i2).name);
    }

    private void updatePhotos(int i) {
        this.currAlbumItemIndex = i;
        this.photoList.clear();
        this.photoList.addAll(this.albumModel.getCurrAlbumItemPhotos(i));
        if (Setting.isShowCamera && !Setting.isBottomRightCamera()) {
            this.photoList.add(0, null);
        }
        this.photosAdapter.change();
        this.rvPhotos.scrollToPosition(0);
    }

    private void shouldShowMenuDone() {
        if (Result.isEmpty()) {
            if (this.tvDone.getVisibility() == 0) {
                ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f);
                scaleAnimation.setDuration(200);
                this.tvDone.startAnimation(scaleAnimation);
            }
            this.tvDone.setVisibility(View.INVISIBLE);
            this.tvPreview.setVisibility(View.INVISIBLE);
        } else {
            if (4 == this.tvDone.getVisibility()) {
                ScaleAnimation scaleAnimation2 = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
                scaleAnimation2.setDuration(200);
                this.tvDone.startAnimation(scaleAnimation2);
            }
            this.tvDone.setVisibility(View.VISIBLE);
            this.tvPreview.setVisibility(View.VISIBLE);
        }
        if (!Result.isEmpty()) {
            if (!Setting.complexSelector || !Setting.complexSingleType) {
                this.tvDone.setText(getString(R.string.selector_action_done_easy_photos, new Object[]{Integer.valueOf(Result.count()), Integer.valueOf(Setting.count)}));
            } else if (Result.getPhotoType(0).contains(Type.VIDEO)) {
                this.tvDone.setText(getString(R.string.selector_action_done_easy_photos, new Object[]{Integer.valueOf(Result.count()), Integer.valueOf(Setting.complexVideoCount)}));
            } else {
                this.tvDone.setText(getString(R.string.selector_action_done_easy_photos, new Object[]{Integer.valueOf(Result.count()), Integer.valueOf(Setting.complexPictureCount)}));
            }
        }
    }

    @Override // com.youyi.yychosesdk.ui.adapter.PhotosAdapter.OnClickListener
    public void onCameraClick() {
        launchCamera(11);
    }

    @Override // com.youyi.yychosesdk.ui.adapter.PhotosAdapter.OnClickListener
    public void onPhotoClick(int i, int i2) {
        PreviewActivity.start(this, this.currAlbumItemIndex, i2);
    }

    @Override // com.youyi.yychosesdk.ui.adapter.PhotosAdapter.OnClickListener
    public void onSelectorOutOfMax(Integer num) {
        if (num != null) {
            int intValue = num.intValue();
            if (intValue == -3) {
                Toast.makeText(getApplicationContext(), getString(R.string.selector_single_type_hint_easy_photos), 0).show();
            } else if (intValue == -2) {
                Toast.makeText(getApplicationContext(), getString(R.string.selector_reach_max_video_hint_easy_photos, new Object[]{Integer.valueOf(Setting.complexVideoCount)}), 0).show();
            } else if (intValue == -1) {
                Toast.makeText(getApplicationContext(), getString(R.string.selector_reach_max_image_hint_easy_photos, new Object[]{Integer.valueOf(Setting.complexPictureCount)}), 0).show();
            }
        } else if (Setting.isOnlyVideo()) {
            Toast.makeText(getApplicationContext(), getString(R.string.selector_reach_max_video_hint_easy_photos, new Object[]{Integer.valueOf(Setting.count)}), 0).show();
        } else if (Setting.showVideo) {
            Toast.makeText(getApplicationContext(), getString(R.string.selector_reach_max_hint_easy_photos), 0).show();
        } else {
            Toast.makeText(getApplicationContext(), getString(R.string.selector_reach_max_image_hint_easy_photos, new Object[]{Integer.valueOf(Setting.count)}), 0).show();
        }
    }

    @Override // com.youyi.yychosesdk.ui.adapter.PhotosAdapter.OnClickListener
    public void onSelectorChanged() {
        shouldShowMenuDone();
    }

    @Override // android.support.v4.app.FragmentActivity
    public void onBackPressed() {
        RelativeLayout relativeLayout = this.rootViewAlbumItems;
        if (relativeLayout == null || relativeLayout.getVisibility() != 0) {
            LinearLayout linearLayout = this.mSecondMenus;
            if (linearLayout == null || linearLayout.getVisibility() != 0) {
                AlbumModel albumModel2 = this.albumModel;
                if (albumModel2 != null) {
                    albumModel2.stopQuery();
                }
                setResult(0);
                finish();
                return;
            }
            processSecondMenu();
            return;
        }
        showAlbumItems(false);
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity
    public void onDestroy() {
        AlbumModel albumModel2 = this.albumModel;
        if (albumModel2 != null) {
            albumModel2.stopQuery();
        }
        super.onDestroy();
    }

    private void setClick(int... iArr) {
        for (int i : iArr) {
            findViewById(i).setOnClickListener(this);
        }
    }

    private void setClick(View... viewArr) {
        for (View view : viewArr) {
            view.setOnClickListener(this);
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:10:0x0011 A[SYNTHETIC, Splitter:B:10:0x0011] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public boolean cameraIsCanUse() {
        /*
            r2 = this;
            android.hardware.Camera r0 = android.hardware.Camera.open()     // Catch:{ Exception -> 0x000d }
            android.hardware.Camera$Parameters r1 = r0.getParameters()     // Catch:{ Exception -> 0x000e }
            r0.setParameters(r1)     // Catch:{ Exception -> 0x000e }
            r1 = 1
            goto L_0x000f
        L_0x000d:
            r0 = 0
        L_0x000e:
            r1 = 0
        L_0x000f:
            if (r0 == 0) goto L_0x0019
            r0.release()     // Catch:{ Exception -> 0x0015 }
            goto L_0x0019
        L_0x0015:
            r0 = move-exception
            r0.printStackTrace()
        L_0x0019:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: com.youyi.yychosesdk.ui.EasyPhotosActivity.cameraIsCanUse():boolean");
    }
}
